$params = $this->extractRequestParams();
$pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
- if ( !$pageObj->exists() ) {
+ $titleObj = $pageObj->getTitle();
+ if ( !$pageObj->exists() &&
+ !( $titleObj->getNamespace() == NS_FILE && self::canDeleteFile( $pageObj->getFile() ) )
+ ) {
$this->dieWithError( 'apierror-missingtitle' );
}
- $titleObj = $pageObj->getTitle();
$reason = $params['reason'];
$user = $this->getUser();
return $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user, $tags );
}
+ /**
+ * @param File $file
+ * @return bool
+ */
+ protected static function canDeleteFile( File $file ) {
+ return $file->exists() && $file->isLocal() && !$file->getRedirected();
+ }
+
/**
* @param Page $page Object to work on
* @param User $user User doing the action
$title = $page->getTitle();
$file = $page->getFile();
- if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
+ if ( !self::canDeleteFile( $file ) ) {
return self::delete( $page, $user, $reason, $tags );
}